import React,{Component} from 'react';
export default class UserDetail extends Component{
    render(){
        console.log(this.props);
        //从路由传过来的  id
        let id = this.props.match.params.id;
        // 从缓存中获取用户列表的字符串  null 字符串
        let userStr = localStorage.getItem('users');
        //转换成对象数组
        let users = userStr?JSON.parse(userStr):[];
        //用id 去寻找这个用户的信息
        let user = users.find(user => user.id == id);
        return (
            <div>
                <table className="table table-bordered table-striped ">
                    <thead>
                        <tr>
                            <td>ID</td>
                            <td>姓名</td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{user.id}</td>
                            <td>{user.name}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        )
    }
};